<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/rp/common/taglib.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>">
    
    <title>数据字典管理</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	
	<script src="rp/scripts/boot.js" type="text/javascript"></script>
	
	<style type="text/css">
	   	
    </style>
	
  </head>
  
  <body class="body-fit">
  	
  	<div class="mini-splitter" style="width: 100%; height: 100%;" borderStyle="border:0;">
  		<div size="220" showCollapseButton="true" minSize="220">
  			<div style="width:100%;">
		        <div class="mini-toolbar" style="padding:1px;border-top:0;border-left:0;border-right:0;">
		            <table style="width:100%;">
		                <tr>
		                    <td style="width:100%;">
		                        <a class="mini-button" onclick="openAddDataDicTypeWindow()"><i class="fa fa-plus fa-lg"></i> 新增类型</a>
		                        <a class="mini-button mini-button-danger" onclick="removeDataDicType()"><i class="fa fa-trash-o fa-lg"></i> 删除</a>
		                    </td>
		                    <td style="white-space:nowrap;">
		                    	
		                    </td>
		                </tr>
		            </table>           
		        </div>
		    </div>
	    	<ul id="dataDicTypeTree" class="mini-tree" url="rp/system/dataDicMng/getAllDataDicType"
	    		style="width:100%;height:100%;" 
			    showTreeIcon="true" textField="text" 
			    idField="id" resultAsTree="false"
			    expandOnLoad="0" onnodeclick="dataDicTypeTreeNodeClick"> 
			</ul>
	    </div>
	    <div showCollapseButton="false">
	    	<div style="width:100%;">
		        <div class="mini-toolbar" style="padding:1px;border-top:0;border-left:0;border-right:0;">
		            <table style="width:100%;">
		                <tr>
		                    <td style="width:100%;">
		                        <a class="mini-button" onclick="addRootNode()"><i class="fa fa-plus fa-lg"></i> 添加根节点</a>
		                        <a class="mini-button" onclick="addChildNode()"><i class="fa fa-plus fa-lg"></i> 添加子节点</a>
		                        <a class="mini-button" onclick="saveRows()"><i class="fa fa-floppy-o fa-lg"></i> 保存</a>
		                        <a class="mini-button mini-button-danger" onclick="removeRows()"><i class="fa fa-trash-o fa-lg"></i> 删除</a>
		                    </td>
		                    <td style="white-space:nowrap;">
		                    	<!-- <a class="mini-button" onclick="search()"><i class="fa fa-search fa-lg"></i> 查询</a> -->
		                    </td>
		                </tr>
		            </table>           
		        </div>
		    </div>
		    <div class="mini-fit">
			  	<div id="dataDicTreeGrid" class="mini-treegrid" style="width: 100%; height: 100%;" borderStyle="border:0;"    
				    url="rp/system/dataDicMng/getDataDicsByTypeBh" showTreeIcon="true"
				    treeColumn="text" idField="id" parentField="pid" 
				    resultAsTree="false" expandOnLoad="false"
			   		allowCellEdit="true" allowCellSelect="true" multiSelect="true"
			       	editNextOnEnterKey="true" editNextRowCell="true" allowCellValid="true">
				    <div property="columns">
				        <div type="indexcolumn" headerAlign="center">序号</div>
				        <div type="checkcolumn" width="20"></div>
				        <div name="text" field="text" vtype="required" width="100" headerAlign="center">
				        	字段文本<input property="editor" class="mini-textbox" style="width:100%;" />
				        </div>
				        <div field="remark" width="200" headerAlign="center" >
				        	备注<input property="editor" class="mini-textarea" style="width:200px;" minWidth="200" minHeight="50"/>
				        </div>
				        <div type="comboboxcolumn" field="typeBh" displayField="typeText" width="50" 
				        	headerAlign="center" align="center" renderer="onTypeRenderer">
				        	所属类型
				        	<input property="editor" class="mini-treeselect" 
				        		popupWidth="160" expandOnLoad="true"
				        		url="rp/system/dataDicMng/getAllDataDicType"
				        		valueField="bh" textField="text" />
				        </div>
				        <div name="sort" field="sort" width="30" headerAlign="center">
				        	排序<input property="editor" class="mini-textbox" style="width:100%;" />
				        </div>
				        <div field="createDate" width="80" headerAlign="center" allowSort="true" renderer="onDateRenderer">
				        	创建日期
				        </div>
				        <!-- <div width="40" headerAlign="center" renderer="onActionRenderer">
				        	操作
				        </div>  -->           
				    </div>
				</div>
			</div>
	    </div>
  	</div>
  	
  	<script type="text/javascript">
  		var grid, dataDicTypeTree;
  	
		$(function(){
			mini.parse();
			grid = mini.get("dataDicTreeGrid");
			dataDicTypeTree = mini.get("dataDicTypeTree");
			grid.load();
		});
		
		function dataDicTypeTreeNodeClick(e){
			var record = e.record;
			grid.load("rp/system/dataDicMng/getDataDicsByTypeBh?typeBh="+record.bh);
		}
		
		function addRootNode() {
			var newNode = { text: "" };
            grid.addNode(newNode, 2);
            grid.beginEditCell(newNode, "text");
		}
		
		function addChildNode() {
			var selectedNode = grid.getSelectedNode();
			grid.expandNode(selectedNode);
			if (!selectedNode) {
				mini.alert("您未选中任何节点");
			} else {
				var newNode = {
					text : ""
				};
				grid.addNode(newNode, "add", selectedNode);
				grid.beginEditCell(newNode, "text");
			}
		}
		
		function saveRows() {
			grid.validate();
			if (grid.isValid() == false) {
				var error = grid.getCellErrors()[0];
				grid.beginEditCell(error.record, error.column);
				return;
			}

			var data = grid.getChanges();
			var json = rp_encode(data);
			grid.loading("保存中，请稍等......");
			rp_ajax("rp/system/dataDicMng/saveDataDics", {
				data : json
			}, function(result) {
				grid.reload();
			});
		}
		
		function removeRows() {
			var rows = grid.getSelecteds();
			if (rows.length == 0) {
				mini.alert("请勾选需要删除的记录...");
			} else {
				mini.confirm("确定删除记录吗？", "友情提示", function(action) {
					if (action == "ok") {
						var json = rp_encode(rows);
						if (rows.length > 0) {
							rp_ajax("rp/system/dataDicMng/deleteDataDics", {
								data : json
							}, function(result) {
								grid.reload();
							});
						}
					}
				});
			}
		}
		
		function removeDataDicType(){
			var selectNode = dataDicTypeTree.getSelectedNode();
			if(selectNode == null){
				mini.alert("请选择需要删除的节点");
			}else{
				
				mini.confirm("确定删除记录吗？", "友情提示", function(action) {
					if (action == "ok") {
						rp_ajax("rp/system/dataDicMng/deleteDataDicType", {typeId:selectNode.id}, function(result){
							if(result == "success"){
								dataDicTypeTree.load();
							}
						});
					}
				});
			}
		}
		
		function openAddDataDicTypeWindow(){
			mini.open({
				url : "rp/system/dataDicMng/dataDicTypeForm.jsp",
				title : "<i class='fa fa-plus fa-lg'></i> 新增类型",
				width : 300,
				height : 160,
				onload : function() {
					//var iframe = this.getIFrameEl();
					//iframe.contentWindow.init();
				},
				ondestroy : function(action) {
					dataDicTypeTree.load();
				}
			});
		}
		
		function onTypeRenderer(e){
			var value = e.cellHtml;
			return value;
		}
		
	</script>
  </body>
</html>